package com.xy.ddd.core.service;

import com.xy.ddd.core.mapper.BaseMapper;
import com.xy.ddd.core.mapper.criteria.LogicCriteria;
import com.xy.ddd.core.model.DomainModel;
import com.xy.ddd.core.po.BasePo;
import com.xy.ddd.core.repository.DefaultRepository;

import java.util.List;

/**
 * 通用领域服务
 * @param <D> 领域模型
 * @param <P> 数据库实体
 * @param <Mapper> Mapper
 */
public abstract class AbstractDomainService<D extends DomainModel, P extends BasePo, Mapper extends BaseMapper<P>>
        extends DefaultRepository<D, P, Mapper> implements IDomainService<D>{

    @Override
    public List<D> findListByField(String fieldName, Object fieldValue) {
        LogicCriteria logicCriteria = new LogicCriteria(convertor.getPoClass());
        logicCriteria.createCriteria().andEqualTo(fieldName, fieldValue);
        return find(logicCriteria);
    }
}
